package com.lagou.guavademo.Controller;

import com.lagou.guavademo.Dao.Mapper.PositionMapper;
import com.lagou.guavademo.Dao.Pojo.Position;
import com.lagou.guavademo.Service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.ExecutionException;

@RestController
public class PositionController {

    @Autowired
    private PositionMapper positionMapper;

    @Autowired
    private PositionService positionService;

    @GetMapping("/position")
    public String show(Integer id) throws ExecutionException {
        String position= positionService.getById(id);
//        return "你好HEy you Spring. id: " + id + " position is: " + position;
        return position;
    }

    @PostMapping(value = "/position", produces = "application/json;charset=UTF-8")
    public Position addPostion(@RequestBody Position position) {
        System.out.println(">>> inserted position: " + position);
        positionService.addNew(position);
        return position;
    }
}
